﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ThucThe;
using DieuKhien;

namespace GiaoDien
{
    public partial class NV_HopDong_sua : Form
    {
        public NV_HopDong_sua()
        {
            InitializeComponent();
        }
        public void loadHopDong(HopDong_thucthe hd_tt, KhachHang_thucthe kh_tt, NhanVien_thucthe nv_tt, Tour_thucthe tour_tt)
        {
            txt_maHD.Text = hd_tt.MaHopDong.ToString();
            cbo_KH.Text = kh_tt.TenKhachHang;
            cbo_KH.SelectedValue = hd_tt.MaKhachHang;
            cbo_Tour.SelectedValue = hd_tt.MaTour;
            cbo_Tour.Text = tour_tt.TenTour;
            cbo_NV.Text = nv_tt.TenNhanVien;
            cbo_Tour.SelectedValue = hd_tt.MaNhanVien;
            dateTime_HD.Text = hd_tt.NgayTao;
        }
        private void button_OK_Click(object sender, EventArgs e)
        {
            try
            {
                HopDong_thucthe hd_tt = new HopDong_thucthe();
                HopDong_dieukhien hd_dk = new HopDong_dieukhien();
                hd_tt.MaKhachHang = int.Parse(cbo_KH.SelectedValue.ToString());
                hd_tt.MaTour = cbo_Tour.SelectedValue.ToString();
                hd_tt.MaNhanVien = int.Parse(cbo_NV.SelectedValue.ToString());
                hd_tt.NgayTao = dateTime_HD.Value.Date.ToString();
                hd_dk.suaHopDong(hd_tt);
                MessageBox.Show("Sửa thành công");
                this.Close();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Nhập đầy đủ các trường");
            }
        }

        private void btn_exitKH_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void button_reset_Click(object sender, EventArgs e)
        {
            txt_maHD.Text = "";
            cbo_KH.Text = "";
            cbo_Tour.Text = "";
            cbo_NV.Text = "";
            dateTime_HD.Text = "";
        }

        private void NV_HopDong_sua_Load(object sender, EventArgs e)
        {
            NhanVien_thucthe nv_tt = new NhanVien_thucthe();
            NhanVien_dieukhien nv_dk = new NhanVien_dieukhien();
            KhachHang_thucthe kh_tt = new KhachHang_thucthe();
            KhachHang_dieukhien kh_dk = new KhachHang_dieukhien();
            Tour_thucthe tour_tt = new Tour_thucthe();
            Tour_dieukhien tour_dk = new Tour_dieukhien();
            HopDong_thucthe hd_tt = new HopDong_thucthe();

            cbo_Tour.DataSource = tour_dk.danhSachTour();
            cbo_Tour.DisplayMember = "tenTour";
            cbo_Tour.ValueMember = "maTour";

            cbo_NV.DataSource = nv_dk.danhSachNhanVien();
            cbo_NV.DisplayMember = "tenNhanVien";
            cbo_NV.ValueMember = "maNhanVien";

            cbo_KH.DataSource = kh_dk.DanhSachKhachHang();
            cbo_KH.DisplayMember = "tenKhachHang";
            cbo_KH.ValueMember = "maKhachHang";
        }
    }
}
